package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.*;
import cn.tedu.blackhorse.pojo.vo.CourseListItemVO;
import cn.tedu.blackhorse.service.ICourseService;
import cn.tedu.blackhorse.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/course")
@Api(tags = "课程表")
@Validated
public class CourseController {

    @Autowired
     ICourseService courseService;

    public CourseController() {
        log.info("创建控制器：CourseController");
    }


    // http://localhost:9088/student/addNew
    @ApiOperation("增加课程")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParam(name = "id", value = "课程id", required = true, dataType = "long")
    @PostMapping("/addNew")
    public JsonResult<Void> addNew(CourseAddNewDTO courseAddNewDTO) {
        log.debug("开始处理【增加课程】的请求");
        courseService.addNew(courseAddNewDTO);
        return JsonResult.ok();
    }
    @ApiOperation("课程列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("")
    public JsonResult<List<CourseListItemVO>> list() {
        log.debug("开始处理【课程列表】的请求");
        List<CourseListItemVO> list = courseService.list();
        return JsonResult.ok(list);
    }
    @ApiOperation("删除课程")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "课程id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除学生】的请求：id={}", id);
        courseService.deleteById(id);
        return JsonResult.ok();
    }
    @ApiOperation("修改课程")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "课程id", required = true, dataType = "long")
    @PostMapping("/update")
    public JsonResult<Void> update(Long id, CourseUpdateDTO courseUpdateDTO) {
        log.debug("开始处理【修改学生信息】的请求");
        courseService.update(id,courseUpdateDTO);
        return JsonResult.ok();
    }
}
